package com.cty;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class regExpression09 {
    public static void main(String[] args) {
        //matcher类中方法的使用
        String content = "juejiangdehouzi juejiangde houzi juejiang";
        String regStr = "juejiang";
        Pattern pattern = Pattern.compile(regStr);
        Matcher matcher = pattern.matcher(content);
        while (matcher.find()) {
            //start()匹配规则的开始位置的偏移量
            System.out.println("=========================");
            System.out.println(matcher.start());
            //end()匹配规则的结束位置的偏移量
            System.out.println(matcher.end());
            String newContent = matcher.replaceAll("倔强");
            //将juejiang的英语换成倔强，生成一个新的字符串，原字符串不变(字符串在底层是常量)
            System.out.println(newContent);
            System.out.println(content);
        }
    }
}
